package com.zhny.aiot.control.cabinet.plugin.factory;

import com.zhny.aiot.control.cabinet.plugin.ControlCabinetConst;
import com.zhny.aiot.control.cabinet.plugin.factory.imp.CheckFactoryImpl;
import com.zhny.aiot.control.cabinet.plugin.factory.imp.ControlFactoryImpl;
import com.zhny.aiot.control.cabinet.plugin.factory.imp.QueryStatusFactoryImpl;
import com.zhny.aiot.control.cabinet.plugin.factory.imp.WriteFactoryImpl;
import com.zhny.aiot.control.cabinet.plugin.model.ControlCabinetStoreEntry;
import com.zhny.aiot.plugin.modbus.device.ModemDevice;
import com.zhny.aiot.plugin.modbus.handler.model.ModemResponseMessage;

public class ControlCabinetFactoryBuild {
    private ModemResponseMessage msg;

    public ControlCabinetFactoryBuild setResponseMessage(ModemResponseMessage modemResponseMessage){
        this.msg=modemResponseMessage;
        return this;
    }
    public ControlCabinetStoreEntry build(ModemDevice device){
//        IControlCabinetFactory factory;

        if(this.msg.getFunction() == ControlCabinetConst.CONTROL){
            return new ControlFactoryImpl().getStoreEntry(msg,device);
        }
        else if(this.msg.getFunction() == ControlCabinetConst.CHECK){
            return new CheckFactoryImpl().getStoreEntry(msg,device);
        }
        else if(this.msg.getFunction() == ControlCabinetConst.QUERY){
            return new QueryStatusFactoryImpl().getStoreEntry(msg,device);
        }
        else if(this.msg.getFunction() == ControlCabinetConst.WRITE){
            return new WriteFactoryImpl().getStoreEntry(msg,device);
        }
        return null;
    }
}
